﻿using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using MonentExam1013.Api.Write.Appliaction.Commond;
using MonentExam1013.ErrorCode;

namespace MonentExam1013.Api.Write.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class QueryController : ControllerBase
    {
        /// <summary>
        /// 中介者
        /// </summary>
        IMediator mediator;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="mediator">中介者</param>
        public QueryController(IMediator mediator)
        {
            this.mediator = mediator;
        }
        /// <summary>
        /// 增加用户
        /// </summary>
        /// <param name="request"> 请求</param>
        /// <returns> 返回</returns>
        [HttpPost]
        public async Task<ApiResult<int>> UserAdd(UserAddCommond request)
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 增加角色
        /// </summary>
        /// <param name="request"> 请求</param>
        /// <returns> 返回</returns>
        [HttpPost]
        public async Task<ApiResult<int>> RoleAdd(RoleAddCommond request)
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 增加权限
        /// </summary>
        /// <param name="request"> 请求</param>
        /// <returns> 返回</returns>
        [HttpPost]
        public async Task<ApiResult<int>> PermissionAdd(PermissionAddCommond request)
        {
            return await mediator.Send(request);
        }
    }
}
